/*
 * MyMenuApp.cpp
 * Created by Sly Silviu-Cristian Dumitru
 * Project: T052 - Menu App
 * Date: Nov 10, 2011
 * Description: 
 */

#include <cstdio>
#include <iostream>
#include "MyMenuApp.h"
#include "Functions.h"

MyMenuApp::MyMenuApp():MenuApp()
{
	AddTitleLine("Lab 1");
	AddTitleLine("By Sly SC Dumitru");
	AddMenuItem("1. Convert Temperature to Celsius", &Celsius);
	AddMenuItem("2. Convert Temperature to Fahrenheit", &Fahrenheit);
	AddMenuItem("3. Quit", Quit);
}

MyMenuApp::~MyMenuApp()
{
}

void MenuApp::AddTitleLine(std::string str)
{
	Title.append(str);
	Title.append("\n");
}

/**
 * Add a new item to the menu and assign a function to it.
 */
void MenuApp::AddMenuItem(std::string str, menu_func fn)
{
	//Add menu item
	Menu.append(str);
	Menu.append("\n");

	//Assign a function to the menu item
	menuItemFunction.push_back(fn);
	menuItemNumber++;
}

/**
 * Run the menu
 */
void MenuApp::Run(void)
{
	DisplayTitle();
	DisplayMenu();

	int n;

	while(true)
	{
		std::cout << "Enter menu number: ";

		std::cin >> n;

		menuItemFunction.at(n - 1)();

	}

}

/**
 * Display the title section
 */
void MenuApp::DisplayTitle(void)
{
	std::cout << Title;
}


/**
 * Display the menu section
 */
void MenuApp::DisplayMenu(void)
{
	std::cout << Menu;
}

MyMenuApp * gp_MyMenuApp;

int main()
{
	MyMenuApp  g_MyMenuApp;

	gp_MyMenuApp = &g_MyMenuApp;

	if(gp_MyMenuApp)
		gp_MyMenuApp->Run();

	return 0;
}
